A factor of a number is an integer that can be multiplied by another integer to produce the original number.
def find_factors(number):
factors = []
for i in range(1, number + 1):
if number % i == 0:
factors.append(i)
return factors
# Taking input for the number and finding its factors
def find_and_display_factors():
number = int(input("Enter a number to find its factors: "))
factors = find_factors(number)
print("Factors of", number, "are:", factors)
find_and_display_factors()
Enter a number to find its factors: 12
Factors of 12 are: [1, 2, 3, 4, 6, 12]
Enter a number to find its factors: 20
Factors of 20 are: [1, 2, 4, 5, 10, 20]
The function find_factors(number)
finds all the factors of a given number.
The function find_and_display_factors()
takes input for the number, finds its factors using the aforementioned function, and displays the result.